package com.ymatou.iapi.productmanager.testcase;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.parameter.ModifyProductNameBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.ModifyProductNameCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.utils.EnvSetup;
/**
*修改商品名称
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ModifyProductName{
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	private static ModifyProductNameBean modifyproductnameBean = new ModifyProductNameBean();
	private static ModifyProductNameCall modifyproductnameCall = new ModifyProductNameCall();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("修改商品名称");
	}

	@Before
	public void caseUp() {
		modifyproductnameBean=new ModifyProductNameBean();
		modifyproductnameCall=new ModifyProductNameCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(modifyproductnameCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyProductName_001() {
		Logger.start(true,"修改商品名称");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String ProductId = ProductManagerCallServiceV3.AddSellerProduct(addProdReq);
			modifyproductnameBean.setProductId(ProductId);
			modifyproductnameBean.setProductName("测试商品007");
			modifyproductnameBean.setSellerId(sellerId);
			modifyproductnameCall.setData(modifyproductnameBean);
			modifyproductnameCall.callService();
			Logger.verifyEquals("200", modifyproductnameCall.getString("Code"), "验证Code");
			modifyproductnameCall.getProductList().forEach(pp->{
				Logger.verifyEquals(ProductId, pp.getProductId(), "验证productId");
				Logger.verifyEquals(modifyproductnameBean.getProductName(), pp.getProductName(), "验证ProductName");
				Logger.verifyEquals(true, pp.getResult(), "验证商品是否成功");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyProductName_002() {
		Logger.start(true,"修改商品名称，商品不是买手创建的");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(3383);
			String ProductId = ProductManagerCallServiceV3.AddSellerProduct(addProdReq);
			modifyproductnameBean.setProductId(ProductId);
			modifyproductnameBean.setProductName("测试商品007");
			modifyproductnameBean.setSellerId(sellerId);
			modifyproductnameCall.setData(modifyproductnameBean);
			modifyproductnameCall.callService();
			Logger.verifyEquals("200", modifyproductnameCall.getString("Code"), "验证Code");
			modifyproductnameCall.getProductList().forEach(pp->{
				Logger.verifyEquals(ProductId, pp.getProductId(), "验证productId");
				//Logger.verifyEquals(modifyproductnameBean.getProductName(), pp.getProductName(), "验证ProductName");
				Logger.verifyEquals(false, pp.getResult(), "验证商品是否成功");
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}